package org.dsapr;

import org.fusesource.jansi.Ansi;

import static org.fusesource.jansi.Ansi.ansi;

public class Grid {
	Cells cells = new Cells();

	public Grid() {
	}

	public void refresh() {
		this.cells.updateState();
	}

	public void draw() {
		System.out.println(ansi().restoreCursorPosition().eraseScreen().render(this.str(this.cells.getMap())));
		System.out.println(ansi().bg(Ansi.Color.GREEN).fgRgb(189, 233, 105).a(Ansi.Attribute.UNDERLINE_OFF).a("LOOP: ").a(Game.loop).reset());
	}

	private String str(boolean[][] cells) {
		StringBuilder cellsString = new StringBuilder();

		for(int i = 0; i < cells.length; ++i) {
			for(int j = 0; j < cells[i].length; ++j) {
				if (cells[i][j]) {
					cellsString.append(Cells.point);
				} else {
					cellsString.append("  ");
				}
			}

			cellsString.append("\n");
		}

		return cellsString.toString();
	}
}
